﻿#pragma once

//===============================================================================
//	可变参数模板的单例模板
//===============================================================================

#include "user_define.h"
#include "log.h"

template<typename T>
class Singleton
{
public:
	template<typename... Args>
	static T* CreateInstance(Args&&... args)
	{
		_safe_guard_begin;

		if (nullptr == m_instance)
		{	
			m_instance = new T(std::forward<Args>(args)...);
		}

		return m_instance;

		_safe_guard_end;

		return nullptr;
	}

	//	获取单例
	static T* GetInstance(void)
	{
		if (!m_instance)
		{
			return nullptr;
		}

		return m_instance;
	}

	static void Destory(void)
	{
		_safe_guard_begin;

		if(m_instance)
		{
			delete m_instance;
		}

		m_instance = nullptr;

		_safe_guard_end;
	}

private:
	Singleton(void);
	virtual ~Singleton(void);
	Singleton(const Singleton&);
	Singleton& operator=(const Singleton&);

private:
	static T * m_instance;
};

template <class T> 
T* Singleton<T>::m_instance = nullptr;